//


#import "MB_DetailsViewController.h"
#import "MB_AddViewController.h"

@interface MB_DetailsViewController ()
/** */
@property (nonatomic, strong) UILabel *datelabe;
/** */
@property (nonatomic, strong) UILabel *contentLabel;
/** */
@property (nonatomic, strong) MB_SqlView *sql;
/** tupian*/
@property (nonatomic, strong) UIImageView *img;

@end

@implementation MB_DetailsViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _sql = [[MB_SqlView alloc]initWithData:@"FirstData" dataName:@"MoodData" success:^{} fail:^(NSError * _Nullable error) {}];
    [self getModelsas];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setnavBatalweeTitle:@"Edit"];
    //
    __weak typeof(self) weakSelf = self;
    [self setupLeftyqwnvjqAndRightSetting:[UIImage imageNamed:@"Edit"] block:^{
        MB_AddViewController *vc =[[MB_AddViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        vc.model = self.model;
        vc.height = UI_NAV_BAR_HEIGHT;
        [weakSelf presentViewController:nav animated:YES completion:nil];
    }];
    
    [self creatView];
    
}

- (void)creatView {
    
    [self.view addSubview:self.img];
    self.datelabe.text = _model.date;
    [self.view addSubview:self.datelabe];
    [self.datelabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRHeight(20)+UI_NAV_BAR_HEIGHT);
        make.left.mas_offset(kRWidth(30));
        make.right.mas_offset(-kRWidth(30));
        make.height.mas_equalTo(kRHeight(20));
    }];
  
    self.contentLabel.text = _model.content;
    [self.view addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.datelabe.mas_bottom).offset(kRHeight(20));
        make.left.mas_offset(kRWidth(30));
        make.right.mas_offset(-kRWidth(30));
    }];
    
}

//
- (UILabel *)datelabe {
    if (!_datelabe) {
        _datelabe = [[UILabel alloc]initWithFrame:CGRectMake(kRWidth(30), kRHeight(30), kMainScreenWidth - kRWidth(60), kRHeight(20))];
        _datelabe.textColor = RGB(155, 155, 155);
        _datelabe.font = FontPFRegular(kRWidth(15));
    }
    return _datelabe;
}
- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.textColor = RGB(90, 99, 90);
        _contentLabel.font = FontPFRegular(kRWidth(16));
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}
- (UIImageView *)img {
    if (!_img) {
        _img = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        _img.image = (UIImage*)_model.img;
    }
    return _img;
}

- (void)getModelsas {
    NSLog(@"%@",_model.id);
    [_sql mb_readEntity:nil ascending:NO filterStr:[NSString stringWithFormat:@"id=%@",_model.id] success:^(NSArray * _Nonnull results) {
        
       FirstData *model = results.firstObject;
       self.contentLabel.text = model.content;
        self.img.image = (UIImage*)model.img;
        
    } fail:^(NSError * _Nullable error) {}];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
